/*
 *  Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com).
 *  <p>
 *  Licensed under the GNU Lesser General Public License 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  <p>
 * https://www.gnu.org/licenses/lgpl.html
 *  <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.kw.admin.controller;

import com.kw.admin.api.feign.RemoteLogService;
import com.kw.admin.api.feign.RemoteTestService;
import com.kw.admin.vo.TestVo;
import com.kw.common.core.util.R;
import com.kw.common.core.util.SpringContextHolder;
import com.kw.common.security.annotation.IgnoreAuth;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author lengleng
 * @date 2018/9/4
 * getTokenPage 管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/test")

public class TestController {

	@Autowired
	private RemoteTestService remoteTestService;

	@IgnoreAuth
	@GetMapping("/testSocket")
	//测试websocket
	public R<Boolean> testSocket() {
		SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
		simpMessagingTemplate.convertAndSendToUser("admin", "/remind", "sss");
		return R.ok();

	}
	//测试ignoreauth作用
	@PostMapping(value = "/testIgnore/{id}")
	@IgnoreAuth
	public R<Boolean> testSocket(String id,@Validated @RequestBody TestVo testVo) {
		SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
		simpMessagingTemplate.convertAndSendToUser("admin", "/remind", "sss");
		return R.ok();

	}
	//测试Validate作用
	@PostMapping(value = "/testValidate")
	@IgnoreAuth
	public R<Boolean> testValidate(String id,@Validated @RequestBody TestVo testVo) {
		SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
		simpMessagingTemplate.convertAndSendToUser("admin", "/remind", "sss");
		return R.ok();

	}

	//测试ignoreauth作用
	@GetMapping("/testIgnore")
	public R<Boolean> getTestIgnore(String id) {
		SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
		simpMessagingTemplate.convertAndSendToUser("admin", "/remind", "sss");
		return R.ok();

	}
	//测试ignoreauth作用
	@PostMapping("/testIgnore")
	public R<Boolean> postTestIgnore(String id) {
		SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
		simpMessagingTemplate.convertAndSendToUser("admin", "/remind", "sss");
		return R.ok();

	}
	//测试内部传递
	@PostMapping("/testInner1")
	public R<String> testInner1(String id) {

		return R.ok(remoteTestService.testInner2().getMsg());

	}
	//测试内部传递
	@PostMapping("/testInner")
	@IgnoreAuth
	public R<String> testInner(String id) {
		return remoteTestService.testInner2();
	}
	@PostMapping("/testInner2")
	public R testInner2(String id) {

		return R.ok(2);

	}



}
